﻿<Window x:Class="MemInsp.MainWindow"
		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
		xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
		xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		Title="Memory Inspector" Height="431" Width="657" Loaded="Window_Loaded" Activated="Window_Activated"
		xmlns:l="clr-namespace:MemoryMapObjects.UI;assembly=MeMapObj"
		xmlns:local="clr-namespace:MemoryMapObjects;assembly=MeMapObj" Icon="/MemInsp;component/Resources/icon_inspector.ico" KeyUp="Window_KeyUp">
	<Window.Resources>
		<ResourceDictionary>
			<local:CustomSizeConverter  x:Key="CustomSizeConverter"/>
			<local:MemoryConverter  x:Key="MemoryConverter"/>
			<DataTemplate x:Key="ProcessesComboBox">
				<StackPanel Orientation="Horizontal">
					<Image Width="25" Height="25" Source="{Binding Path=Icon}" />
					<Label Width="150" Height="25" Content="{Binding Path=ProcessName}" />
					<Label Width="50" Height="25" Content="{Binding Path=ProcessId}" />
				</StackPanel>
			</DataTemplate>
			<Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
				<Setter Property="OverridesDefaultStyle" Value="true"/>
				<Setter Property="HasDropShadow" Value="True"/>
				<Setter Property="Template">
					<Setter.Value>
						<ControlTemplate TargetType="ToolTip">
							<Border CornerRadius="7" HorizontalAlignment="Center" VerticalAlignment="Top" Padding="5" BorderThickness="3,3,3,3">
								<Border.Background>
									<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
										<GradientStop Color="#CF181818" Offset="0"/>
										<GradientStop Color="#BE1C1C1C" Offset="1"/>
									</LinearGradientBrush>
								</Border.Background>
								<Border.BorderBrush>
									<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
										<GradientStop Color="#80FFFFFF" Offset="0"/>
										<GradientStop Color="#7FFFFFFF" Offset="1"/>
										<GradientStop Color="#FFFFF18D" Offset="0.344"/>
										<GradientStop Color="#FFFFF4AB" Offset="0.647"/>
									</LinearGradientBrush>
								</Border.BorderBrush>
								<Grid>
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="*">
										</ColumnDefinition>
										<ColumnDefinition Width="2*"></ColumnDefinition>
									</Grid.ColumnDefinitions>
									<Grid.RowDefinitions>
										<RowDefinition Height="auto"></RowDefinition>
										<RowDefinition Height="auto"></RowDefinition>
										<RowDefinition Height="auto"></RowDefinition>
										<RowDefinition Height="auto"></RowDefinition>
										<RowDefinition Height="auto"></RowDefinition>
									</Grid.RowDefinitions>
									<TextBlock FontFamily="Tahoma" FontSize="14" Text="Module:  "  Grid.Row="0" Grid.Column="0" Foreground="#FFFFFFFF"/>
									<TextBlock FontFamily="Tahoma" FontSize="14" Text="{Binding Name}"  Grid.Row="0" Grid.Column="1" Foreground="#FFFFFFFF"/>
									<TextBlock FontFamily="Tahoma" FontSize="14" Text="Size of Image:  "  Grid.Row="1" Grid.Column="0" Foreground="#FFFFFFFF"/>
									<TextBlock FontFamily="Tahoma" FontSize="14" Text="{Binding SizeOfImage, Converter={StaticResource MemoryConverter}}"  Grid.Row="1" Grid.Column="1" Foreground="#FFFFFFFF"/>
									<TextBlock FontFamily="Tahoma" FontSize="14" Text="Entry Point:  "  Grid.Row="2" Grid.Column="0" Foreground="#FFFFFFFF"/>
									<TextBlock FontFamily="Tahoma" FontSize="14" Text="{Binding EntryPointInHex}"  Grid.Row="2" Grid.Column="1" Foreground="#FFFFFFFF"/>
									<TextBlock FontFamily="Tahoma" FontSize="14" Text="Base Address:  "  Grid.Row="3" Grid.Column="0" Foreground="#FFFFFFFF"/>
									<TextBlock FontFamily="Tahoma" FontSize="14" Text="{Binding BaseOfDllInHex}"  Grid.Row="3" Grid.Column="1" Foreground="#FFFFFFFF"/>
									<TextBlock FontFamily="Tahoma" FontSize="14" Text="File location:  "  Grid.Row="4" Grid.Column="0" Foreground="#FFFFFFFF"/>
									<TextBlock FontFamily="Tahoma" FontSize="14" Text="{Binding ImagePath}"  Grid.Row="4" Grid.Column="1" Foreground="#FFFFFFFF"/>
								</Grid>
							</Border>
						</ControlTemplate>
					</Setter.Value>
				</Setter>
			</Style>
		</ResourceDictionary>
	</Window.Resources>
	<VisualStateManager.VisualStateGroups>
		<VisualStateGroup x:Name="Activity">
			<VisualState x:Name="IsLoaded">
				<Storyboard>
					<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="Loader">
						<DiscreteObjectKeyFrame KeyTime="0:0:0.75" Value="{x:Static Visibility.Collapsed}" />
					</ObjectAnimationUsingKeyFrames>
					<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Loader" Duration="0:0:0.75">
						<EasingDoubleKeyFrame Value="0" />
					</DoubleAnimationUsingKeyFrames>
				</Storyboard>
			</VisualState>
			<VisualState x:Name="IsLoading">
				<Storyboard>
					<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility" Storyboard.TargetName="Loader">
						<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
					</ObjectAnimationUsingKeyFrames>
					<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Loader" Duration="0:0:0.75">
						<EasingDoubleKeyFrame Value="1" />
					</DoubleAnimationUsingKeyFrames>
				</Storyboard>
			</VisualState>
		</VisualStateGroup>
	</VisualStateManager.VisualStateGroups>
	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="363*" />
		</Grid.RowDefinitions>
		<Grid x:Name="grdContainer" >
			<Grid.RowDefinitions>
				<RowDefinition Height="65" />
				<RowDefinition Height="363*" />
				<RowDefinition Height="20" />
			</Grid.RowDefinitions>
			<Grid>
				<Grid.RowDefinitions>
					<RowDefinition Height="25" />
					<RowDefinition Height="40" />
					<RowDefinition Height="0*" />
				</Grid.RowDefinitions>
				<Menu Grid.Row="0" VerticalAlignment="Top">
					<MenuItem Header="File">
						<MenuItem Header="Run..." Name="RunDialog" Click="menuItem_Clicked"/>
						<MenuItem Header="Save..." Name="Save">
							<MenuItem Header="as an image..." Name="SaveImage" Click="menuItem_Clicked"/>
							<MenuItem Header="as an xml file..." Name="SaveXml" Click="menuItem_Clicked"/>
						</MenuItem>
						<MenuItem Header="Exit" Name="Exit" Click="menuItem_Clicked"/>
					</MenuItem>
					<MenuItem Header="Find (F3)" Name="_Find" Click="menuItem_Clicked"/>
					<MenuItem Header="Help">
						<MenuItem Header="Color Key..."  Name="ColorKey"  Click="menuItem_Clicked"/>
						<MenuItem Header="About Windows..."  Name="AboutBox"  Click="menuItem_Clicked"/>
						<MenuItem Header="About Memory Inspector..."  Name="AboutThisApp"  Click="menuItem_Clicked"/>
					</MenuItem>
				</Menu>
				<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="1">
					<Label Name="lblSelectedProcess"  Content="Selected Process: " Margin="3,0,3,0" Height="24" />
					<ComboBox  Name="cboProcesses" Margin="3,0,3,0" Width="200" SelectionChanged="cboProcesses_SelectionChanged" 
						   ItemsSource="{Binding ProcessInfoCollection}" Height="32" ItemTemplate="{StaticResource ProcessesComboBox}"/>
					<Button  Name="btnRefresh" Content="Refresh" Margin="3,0,3,0" Width="75" Click="btnRefresh_Click" Height="23" />
				</StackPanel>
			</Grid>
			<ScrollViewer Grid.Row="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Name="scroller" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" Grid.RowSpan="2">
				<ItemsControl Name="loadedModules" VirtualizingStackPanel.IsVirtualizing="False">
					<ItemsControl.ItemTemplate>
						<DataTemplate>
							<Border BorderBrush="Black" BorderThickness="0.5" CornerRadius="2" >
								<Border.ContextMenu>
									<ContextMenu Name="mnuOptions">
										<MenuItem Name="ShowInExplorer"  Header="Show in Windows Explorer" Click="menuItem_Clicked"/>
										<MenuItem Name="ShowExportedFunctions" Header="Show exported functions/methods" Click="menuItem_Clicked"/>
										<MenuItem Name="DisplayMemory" Header="Display memory" Click="menuItem_Clicked"/>
										<MenuItem Name="FileProperties" Header="Properties..." Click="menuItem_Clicked"/>
										<MenuItem Name="SearchOnline" Header="Search Online..." Click="menuItem_Clicked"/>
									</ContextMenu>
								</Border.ContextMenu>
								<Label  Content="{Binding Name}" Background="{Binding Color}" Width="{Binding SizeOfImage, Converter={StaticResource CustomSizeConverter}}" ToolTip="{Binding .}"></Label>
							</Border>
						</DataTemplate>
					</ItemsControl.ItemTemplate>
					<ItemsControl.ItemsPanel>
						<ItemsPanelTemplate>
							<WrapPanel></WrapPanel>
						</ItemsPanelTemplate>
					</ItemsControl.ItemsPanel>
				</ItemsControl>
			</ScrollViewer>
			<l:Loader Grid.Row="1" Grid.RowSpan="3" x:Name="Loader"  
			       Visibility="Collapsed" 
			       Opacity="0"/>
		</Grid>
		<StatusBar VerticalAlignment="Bottom">
			<StatusBarItem>
				<Bold>
					<TextBlock Name="lblStatus" Width="auto"/>
				</Bold>
			</StatusBarItem>
		</StatusBar>
	</Grid>
</Window>